import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from './components/Home'
import Menu from './components/Menu'
import Admin from './components/Admin'
import AboutUs from './components/aboutus/AboutUs'
import Login from './components/Login'
import Registered from './components/Registered'
import HistoricalOrder from './components/aboutus/children/HistoricalOrder'
import ContactUs from './components/aboutus/children/ContactUs'
import OrderDocument from './components/aboutus/children/OrderDocument'
import ExpressDelivery from './components/aboutus/children/ExpressDelivery'
import store from './store/store'

//  全局注册
Vue.use(VueRouter)

//  路由配置
export const router = new VueRouter({   //  export公开
    mode: "history",
    routes: [
    {path: "*", redirect: "/"},
        {name: "Home", path: "/", components: {default: Home,HistoricalOrder,ContactUs,OrderDocument,ExpressDelivery}},
        {name: "Menu", path: "/menu", component: Menu},
        {name: "Admin", path: "/admin", component: Admin},
        {name: "AboutUs", path: "/aboutus", redirect: "/aboutus/historicalorder", component: AboutUs, children: [
            {name: "HistoricalOrder", path: "/aboutus/historicalorder", component: HistoricalOrder},
            {name: "ContactUs", path: "/aboutus/contactus", component: ContactUs},
            {name: "OrderDocument", path: "/aboutus/orderdocument", component: OrderDocument},
            {name: "ExpressDelivery", path: "/aboutus/expressdelivery", component: ExpressDelivery},
        ]},
        {name: "Login", path: "/login", component: Login},
        {name: "Registered", path: "/registered", component: Registered}
    ]
})

//  路由全局守卫
router.beforeEach((to, from, next) => {
    if(localStorage.getItem("bmob")) {
        next();
    }else {
        to.name == "Registered" || to.name == "Login" ? next() : next({name: "Login"});
    }
})

//  全部进行供出
export default router